// 获取用户信息
function getUserInfo() {
    axios({
        method: 'get',
        url: '/my/userinfo'
    }).then(res => {
        // 1. 结构出username
        let { username, nickname, user_pic } = res.data.data
            // 2. 渲染头像
        let x = null
        if (user_pic) {
            $('.layui-nav-img').attr('src', user_pic).show()
            $('.user_span').hide()
        } else if (nickname) {
            x = nickname.slice(0, 1)
            $('.layui-nav-img').hide()
            $('.user_span').html(x).show()
        } else {
            x = username.slice(0, 1)
            $('.layui-nav-img').hide()
            $('.user_span').html(x).show()
        }
        // 3. 渲染用户后面的用户名或者昵称
        if (nickname) {
            $('.username').html(nickname)
        } else {
            $('.username').html(username)
        }
        console.log(res);
    })
}
getUserInfo()

// 点击退出登陆
$('.loginOut').on('click', () => {
    localStorage.removeItem('token')
    location.href = '../login/login.html'
})